package com.isoft.service.impl;

import com.isoft.service.XmlFileHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

@Component
public class DefaultXmlFileHandler implements XmlFileHandler {      //默认XML文件处理器
    private static final Logger logger = LoggerFactory.getLogger(DefaultXmlFileHandler.class);

    @Override
    public boolean supports(Path filePath) {
        // 只处理非.xml结尾的文件，避免抢占所有xml文件
        return !filePath.getFileName().toString().toLowerCase().endsWith(".xml");
    }

    @Override
    public String handle(Path filePath) throws Exception {
        logger.info("Processing generic file (非xml): {}", filePath);

        Path processedDir = filePath.getParent().resolve("processed");
        Files.createDirectories(processedDir);
        Path target = processedDir.resolve(filePath.getFileName());
        Files.move(filePath, target, StandardCopyOption.REPLACE_EXISTING);

        return "Generic file processed and moved to: " + target;
    }
}
